/**
 *
 */
package com.zhuoyue.elmt.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.zhuoyue.elmt.entity.MaintenanceContractDevice;
import com.zhuoyue.elmt.entity.MaintenanceRecordItem;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.service.CrudService;
import com.zhuoyue.elmt.entity.MaintenanceContract;
import com.zhuoyue.elmt.dao.MaintenanceContractDao;

/**
 * 维保合同备案Service
 *
 * @author chenhao
 * @version 2016-09-08
 */
@Service
@Transactional(readOnly = true)
public class MaintenanceContractService extends CrudService<MaintenanceContractDao, MaintenanceContract> {

    public MaintenanceContract get(String id) {
        return super.get(id);
    }

    public List<MaintenanceContract> findList(MaintenanceContract maintenanceContract) {
        return super.findList(maintenanceContract);
    }

    public List<HashMap> findContractDeviceList(MaintenanceContractDevice maintenanceContractDevice) {
        return dao.findContractDeviceList(maintenanceContractDevice);
    }

    public Page<MaintenanceContract> findPage(Page<MaintenanceContract> page, MaintenanceContract maintenanceContract) {
        return super.findPage(page, maintenanceContract);
    }

    @Transactional(readOnly = false)
    public void save(MaintenanceContract maintenanceContract) {
        super.save(maintenanceContract);
    }

    @Transactional(readOnly = false)
    public void delete(MaintenanceContract maintenanceContract) {
        //删除现有的维保合同设备
        dao.deleteMaintenanceContractDeviceByContractId(maintenanceContract.getId());

        super.delete(maintenanceContract);
    }

    //获取维保合同设备
    public List<HashMap> findMaintenanceContractDevice(HashMap params) {
        return dao.findMaintenanceContractDevice(params);
    }

    @Transactional(readOnly = false)
    public List<MaintenanceContract> findEffectiveDeviceList(MaintenanceContract maintenanceContract) {
        return dao.findEffectiveDeviceList(maintenanceContract);
    }

    @Transactional(readOnly = false)
    public void saveWbMaintenanceItemList(String contractId, ArrayList<HashMap> array) {
        //删除现有的维保合同设备
        dao.deleteMaintenanceContractDeviceByContractId(contractId);
        //重新添加维保合同设备
        for (HashMap model : array) {
            dao.insertMaintenanceContractDevice(model);
        }
    }

}